<%@page import="org.shop.entity.security.MyUserDetail" %>
<%@page import="org.shop.util.ObjUtil" %>
<%@page import="org.springframework.security.core.context.SecurityContextImpl" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";

    SecurityContextImpl securityContextImpl = (SecurityContextImpl) request.getSession().getAttribute("SPRING_SECURITY_CONTEXT");
    MyUserDetail ud = null;
    Byte state = 1;
    if (ObjUtil.isNotNullAndEmpty(securityContextImpl)) {
        ud = (MyUserDetail) securityContextImpl.getAuthentication().getPrincipal();
        state = ud.getState();
    }
%>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1 user-scalable=0">
    <title>招聘</title>
    <link rel="stylesheet" href="<%=basePath%>assets/css/public.css">
    <link rel="stylesheet" href="<%=basePath%>assets/css/page.css">
    <link rel="stylesheet" href="<%=basePath%>assets/font-awesome-4.7.0/css/font-awesome.min.css">
    <script src="<%=basePath%>assets/js/jquery-1.8.3.min.js"></script>
    <script src="<%=basePath%>assets/js/fontSize.js"></script>
    <link href="<%=basePath%>/assets/layer/mobile/need/layer.css" rel="stylesheet" type="text/css">
	<script src="<%=basePath%>/assets/layer/mobile/layer.js"></script>
    <style>
        body {
            padding-top: 0.8rem;
            padding-bottom: 1.6rem;
        }

        .header_ul li {
            float: left;
            width: 25%;
        }

        .header_ul li a {
            font-size: 0.28rem;
            height: 0.75rem;
            line-height: 0.8rem;
            padding: 0 0.2rem;
            display: inline-block;
        }

        .header_ul li a.active {
            color: #FF3D20;
            border-bottom: 2px solid #FF3D20;
        }
        .search_job{
            padding:0.2rem;
        }
        .search_job input{
            float: left;
            width: 84%;
            height: 0.6rem;
            border: 1px solid #EEEEEE;
            border-radius: 0.2rem;
            padding-left: 2%;
        }
        .search_job button{
            float: right;
            width: 12%;
            border: none;
            height: 0.6rem;
            outline: none;
            background: #fff;
            font-size: 0.26rem;
        }

        .job_list {
            padding: 0 0.2rem;
        }
        .job_info{
            position: relative;
        }

        .job_name {
            font-size: 0.26rem;
            line-height: 0.36rem;
        }

        .point_info {
            height: 0.8rem;
            line-height: 0.4rem;
        }
        .pay{
            position: absolute;
            top:0.2rem;
            right:0.2rem;
            font-size: 0.28rem;
            color: #FF2828;
        }
        .pay i{
            font-size: 0.3rem;
        }

        .name {
            font-size: 0.2rem;
            color: #747474;
        }

        .time {
            color: #BABABA;
            font-size: 0.2rem;
        }

        .position {
            background-image: url("<%=basePath%>assets/images/point.png");
            width: 0.2rem;
            height: 0.2rem;
            display: inline-block;
            background-size: cover;
            margin-right: 4px;
            margin-top: 4px;
        }

        .clock {
            background-image: url("<%=basePath%>assets/images/clock.png");
            width: 0.2rem;
            height: 0.2rem;
            display: inline-block;
            background-size: cover;
            margin-right: 4px;
            margin-top: 4px;
        }
        .photo {
            width: 0.8rem;
        }
        .company{
            margin: 0.2rem 0;
        }
        .job_name{
            line-height: 0.6rem;
        }

        .photo img {
            width: 0.8rem;
            height: 0.8rem;
            border-radius: 50%;
        }

        .company_name {
            font-size: 0.24rem;
        }

        .company_time {
            color: #989898;
            font-size: 0.2rem;
        }
        .info{
            line-height: 0.4rem;
            margin-left: 0.1rem;
        }
        .fixed_btn {
            width: 0.6rem;
            height: 0.6rem;
            border-radius: 50%;
            position: fixed;
            right: 0.4rem;
            bottom: 1.2rem;
        }

        .fixed_btn img {
            width: 100%;
        }
        .find a .img{
            display: none;
        }
        .find a .img2{
            display: block;
        }
        .find a p{
            color: #FF3F25;
        }
    </style>
</head>
<body>
<input id="basePath" type="hidden" value="<%=basePath%>">
<div class="header">
    <ul class="header_ul">
        <li class="forum"><a>论坛</a></li>
        <li class="question_answer"><a>问答</a></li>
        <li class="activity"><a>活动</a></li>
        <li class="invite"><a class="active">招聘</a></li>
    </ul>
</div>
<div class="search_job clearFirx border-bottom-8">
    <input type="text" placeholder="你感兴趣的工作" id="searchWork">
    <button onclick="searchWork()">搜索</button>
</div>
<div class="job_list">

</div>
<div class="fixed_btn">
    <img src="<%=basePath%>assets/images/add.png" alt="" onclick="issue()">
</div>
<%@ include file="../footer.jsp" %>
</body>
<script>
	//滚动加载
	var geting = false;//是否加载信息，默认为false
	var currentPage = 1;//当前页
	var pageSize = 10;//每页数据数
	//滚动加载2
	var geting2 = false;//是否加载信息，默认为false
	var currentPage2 = 1;//当前页
	var pageSize2 = 10;//每页数据数
	$(function(){
		
		$(".header_ul a").click(function () {
	        $(".header_ul a").removeClass("active");
	        $(this).addClass("active");
	    });
	    $(".forum").click(function () {
	        window.location.href = "<%=basePath%>jsp/app/find/forum.jsp";
	    });
	    $(".question_answer").click(function(){
	        window.location.href="<%=basePath%>jsp/app/find/questionsAnswers.jsp";
	    });
	    $(".activity").click(function () {
	        window.location.href = "<%=basePath%>jsp/app/find/activity.jsp";
	    });
	    $(".job_info").click(function () {
	        window.location.href = "<%=basePath%>jsp/app/find/job_details.jsp";
	    });
	    $(".fixed_btn").click(function () {
	        window.location.href = "<%=basePath%>jsp/app/find/publish_job.jsp";
	    });
		
		
		getData();
		//加载方法
		$(window).scroll(function () {
			if (geting) {
	        	return;
	        }
	        var scrollTop = $(this).scrollTop();
	        var scrollHeight = $(document).height();
	        var windowHeight = $(this).height();
	        if (scrollTop + windowHeight == scrollHeight) {
	        	currentPage++;
	            getData();
	        }
	    });
		
	});
	
	
	//获取页面数据
	function getData() {
    	geting = true;
    	
    	$.ajax({
			url : "<%=basePath%>app/getRecruitmentList",
			async:false,
			dataType : "json",
			type : "post",
			data : {
				"currentPage" : currentPage,
				"pageSize" : pageSize
			},
			success : function(data) {
				$.each(data, function (i, item) {
					var settlement = '';
					var ImgStr = '';
					if(item.settlementWay==0){
						settlement = item.salary+'/日';
					}else {
						settlement = item.salary+'/月';
					}
					if(item.userHeadImg==null||item.userHeadImg==''){
						ImgStr = '<img src="<%=basePath%>assets/images/timg(2).jpg" alt="">';
					}else{
						ImgStr = '<img src="<%=basePath%>app/getGoodsPhotoByName?goodsImage='+item.userHeadImg+'" alt="">';
					}
					var html = '<div class="job_info border-bottom-1" onclick="toRecruitmentDetails('+item.recruitmentId+')">'+
				            '<div class="job_name">'+
				                ''+item.jobName+''+
				            '</div>'+
				            '<div class="point_info">'+
				                '<span class="name"><i class="position float_l"></i>'+item.workPlace+'</span><br>'+
				                '<span class="time"><i class="clock float_l"></i>'+item.wordTime+'</span>'+
				            '</div>'+
				            '<div class="company clearFirx">'+
				            	'<div class="photo float_l">'+
			                		''+ImgStr+''+
			            		'</div>'+
			            		'<div class="info float_l">'+
					                '<span class="company_name">'+item.userName+'</span><br>'+
					                '<span class="company_time">'+item.createDate+'</span>'+
				            	'</div>'+
				            '</div>'+
				            '<div class="pay">'+
			                	'<i class="fa fa-rmb"></i>'+settlement+''+
			            	'</div>'+
				        '</div>';
					$(".job_list").append(html);
					geting = false;
				});
			},
			error : function(data) {
				layer.open({
				    content: '网络错误~'
				    ,skin: 'msg'
				    ,time: 3 //3秒后自动关闭
				  });
			}
		})
	};
    
	//搜索工作
	function searchWork(){
		$(".job_list").empty();
		var searchWork = $("#searchWork").val();
		geting = true;
		$.ajax({
			url : "<%=basePath%>app/getRecruitmentList",
			async:false,
			dataType : "json",
			type : "post",
			data : {
				"currentPage" : currentPage2,
				"jobName" : searchWork,
				"pageSize" : pageSize2
			},
			success : function(data) {
				$.each(data, function (i, item) {
					var settlement = '';
					var ImgStr = '';
					if(item.settlementWay==0){
						settlement = item.salary+'/日';
					}else {
						settlement = item.salary+'/月';
					}
					if(item.userHeadImg==null||item.userHeadImg==''){
						ImgStr = '<img src="<%=basePath%>assets/images/timg(2).jpg" alt="">';
					}else{
						ImgStr = '<img src="<%=basePath%>app/getGoodsPhotoByName?goodsImage='+item.userHeadImg+'" alt="">';
					}
					var html = '<div class="job_info border-bottom-1" onclick="toRecruitmentDetails('+item.recruitmentId+')">'+
				            '<div class="job_name">'+
				                ''+item.jobName+''+
				            '</div>'+
				            '<div class="point_info">'+
				                '<span class="name"><i class="position float_l"></i>'+item.workPlace+'</span><br>'+
				                '<span class="time"><i class="clock float_l"></i>'+item.wordTime+'</span>'+
				            '</div>'+
				            '<div class="company clearFirx">'+
				            	'<div class="photo float_l">'+
			                		''+ImgStr+''+
			            		'</div>'+
			            		'<div class="info float_l">'+
					                '<span class="company_name">'+item.userName+'</span><br>'+
					                '<span class="company_time">'+item.createDate+'</span>'+
				            	'</div>'+
				            '</div>'+
				            '<div class="pay">'+
			                	'<i class="fa fa-rmb"></i>'+settlement+''+
			            	'</div>'+
				        '</div>';
					$(".job_list").append(html);
					geting = false;
				});
			},
			error : function(data) {
				layer.open({
				    content: '网络错误~'
				    ,skin: 'msg'
				    ,time: 3 //3秒后自动关闭
				  });
			}
		})
	};
	
	//跳转招聘详情
	function toRecruitmentDetails(recruitmentId){
		window.location.href = "<%=basePath%>/app/toJobDetails?recruitmentId="+recruitmentId;
	}
	
</script>
</html>
